package com.ordos.recruit.module.user.util;

import com.ordos.recruit.module.user.constant.Conf;
import com.ordos.recruit.module.user.entity.SysSsoUserDto;
import com.ordos.recruit.module.user.helper.SsoLoginStoreHelper;
import com.ordos.recruit.module.user.helper.SsoSessionIdHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * 提供的用户工具类.
 *
 * @author jn
 */
public class UserUtil {

    /**
     * 根据SessionId获取用户信息.
     *
     * @param sessionId sessionId
     * @return 用户信息.
     */
    public static SysSsoUserDto getUserBySessionId(String sessionId) {
        String storeKey = SsoSessionIdHelper.parseStoreKey(sessionId);
        return SsoLoginStoreHelper.get(storeKey);
    }

    /**
     * 根据当前请求, 获取用户信息.
     *
     * @return SsoUser
     */
    public static SysSsoUserDto getUserByRequest() {
        HttpServletRequest request = RequestUtils.getRequest();
        String cookieSessionId = request.getHeader(Conf.SSO_SESSIONID);
        return getUserBySessionId(cookieSessionId);
    }
}
